<?php
//PLUGIN type=backend
//PLUGIN name=library.indexer 1.5
//PLUGIN desc=Adds library index variables to template engine & since 1.3 sorts into groups. A JSON string can be fetched by ajax request.
//PLUGIN group=native

/*
 * This plugin is old and still uses the $_GET variable instead of the $options variable.
 * For now, keep it this way. Its a lot of work to change since all the calls from javascript would have to be rewritten
 */

global $smarty;

$call_url = "call.php?file=plugins/backend.library.indexer.php&json=true&folder=";
$dialog_url = "call.php?file=plugins/backend.library.indexer.php&dialog=true";
if (isset($_GET['json']))
{
    $folder = "";
    if (isset($_GET['folder']))
        $folder = $_GET['folder'];


    $lib_images = array();
    $lib_folders = array();
    if (!is_array($lib_img_temp = glob(_LIBRARYPATH_ . '/images' . $folder . '/*')))
        $lib_img_temp = array();
    foreach ($lib_img_temp as $i)
    {
        if (is_file($i))
            $lib_images[] = substr($i, strlen(_LIBRARYPATH_ . "/images"));
        else
            $lib_folders[] = substr($i, strlen(_LIBRARYPATH_ . "/images"));
    }
    $json_array = array(
        'location' => $folder,
        'images' => $lib_images,
        'folders' => $lib_folders
    );
    print json_encode($json_array);
}
if (isset($smarty))
{
    $smarty->assign("libraryCallUrl", $call_url);
    $smarty->assign("libraryDialogUrl", $dialog_url);
}
if (isset($_GET['dialog']))
{
    $smarty->display("cms.library.3.dialog.tpl");
}
?>